package cn.wolfcode.trip.app.util;


import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

//用户操作工具类
public class UserContext {

    //session中员工常量
    public static final String USER_IN_SESSION = "USER_IN_SESSION";

    public static HttpSession getSession(){
       return ((ServletRequestAttributes) RequestContextHolder.
               getRequestAttributes()).getRequest().getSession();
    }

    //获取当前登录的用户, 将用户设置到session
    public static User getCurrentUser(){
        return (User) getSession().getAttribute(USER_IN_SESSION);
    }

    //设置当前登录的用户, 将用户设置到session
    public static void setCurrentUser(User user){
        getSession().setAttribute(USER_IN_SESSION, user);
    }

}
